package com.example.manu_facturer_orders.controller;

import cn.hutool.json.JSONUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.manu_facturer_orders.pojo.OrderTableVO;
import com.example.manu_facturer_orders.pojo.PageResult;
import com.example.manu_facturer_orders.service.OrderTableService;
import commons.Result;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pojo.OrderTable;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @author: tobed
 * @date: 2022/9/11
 * @time: 19:18
 */
@RestController
@RequestMapping("orderTable")
public class OrderTableController {

    @Autowired
    OrderTableService orderTableService;

    /**
     * 单厂商订单全查
     * @return
     */
    @RequestMapping("listById")
    public Result list(
            @RequestParam Integer id,
            @RequestParam String date,
            PageResult pageResult){
        Page<OrderTableVO> list = orderTableService.list(id,date.substring(0,10),new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(list);
    }

    /**
     * 通过日期单查
     * @param date
     * @param pageResult
     * @return
     */
    @RequestMapping("listByDate")
    public Result listByDate(
            @RequestParam String date,
            PageResult pageResult){
        Page<OrderTableVO> list = orderTableService.listByDate(date.substring(0,10),new Page<>(pageResult.getPageNum(), pageResult.getPageSize()));
        return Result.success(list);
    }

    /**
     * 导出订单
     * @param date
     * @param id
     * @return
     */
    @ApiOperation(value = "导出excel")
    @GetMapping("export")
    public void export(
            HttpServletResponse response,
            @RequestParam Integer id,
            @RequestParam String date,
            XSSFWorkbook workbook) throws Exception{
        System.out.println("66666");
       orderTableService.listByIdAndDate(id,date.substring(0,10),response,workbook);
    }


}
